<template>
  <div class="mui-numbox" data-numbox-min="1" style="height:25px">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input
      id="test"
      class="mui-input-numbox"
      type="number"
      :value="initcount"
      ref="nobox"
      @change="countChanged"
    />
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
// 导入mui,从而支持初始化数字框
import mui from "../../../lib/mui/js/mui.js";
import { mapMutations } from "vuex";
export default {
  data() {
    return {};
  },
  methods: {
    countChanged() {
      const val = parseInt(this.$refs.nobox.value);
      // 调用 mutations 方法 来更新数量
      this.updateGoodsCount({ id: this.id, count: val });
    },
    ...mapMutations(["updateGoodsCount"]),
  },
  mounted() {
    mui(".mui-numbox").numbox();
  },
  props: ["initcount", "id"],
};
</script>

<style lang="scss" scoped>
</style>